//
//  ZLWelcomeView.swift
//  ZLWeibo
//
//  Created by zhanglongtao on 16/12/26.
//  Copyright © 2016年 hanju001. All rights reserved.
//

import UIKit
import SDWebImage

class ZLWelcomeView: UIView {

    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var tipLabel: UILabel!
    
    @IBOutlet weak var bottomConsatant: NSLayoutConstraint!
    
    class func welcomeView() -> ZLWelcomeView{
        
        let nib = UINib(nibName: "ZLWelcomeView", bundle: nil)
        
        let v: ZLWelcomeView = nib.instantiate(withOwner: nil, options: nil)[0] as! ZLWelcomeView
        
        v.frame = UIScreen.main.bounds
        
        return v
        
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        //只是从xib的二进制文件将视图数据加载完
        //还没有和代码连线建立视图关系，不要在这个方法中处理UI
        
    }
    override func awakeFromNib() {
        
        guard let url = ZLNetWorkManager.shared.userAcount.avatar_large else {
            
            return
        }
        //iconView.sd_setImage(with: URL(string: url))
        iconView.sd_setImage(with: URL(string: url), placeholderImage: UIImage(named: "avatar_default_big"))
        
        iconView.layer.cornerRadius = 85/2.0
        iconView.layer.masksToBounds = true
        
        
    }
    //视图被添加到window上
    override func didMoveToWindow() {
       super.didMoveToWindow()
        
        self.layoutIfNeeded()
        
        bottomConsatant.constant = bounds.size.height - 200;
        UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            
            
            self.layoutIfNeeded()
            
        }) { (_) in
            
            UIView.animate(withDuration: 1.0, animations: { 
                
                self.tipLabel.alpha = 1.0
            }, completion: { (_) in
                
                self.removeFromSuperview()
            })
        }
        
    }

}
